import request from '@/utils/request'
import store from '@/store'
//const ascriptionId = store.state.userInfo.ascriptionId;

// 页面内容 左侧树 课程分类 树列表数据
export function getPage(queryParams) {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
    currentPage: queryParams.currentPage,
    pagesize: queryParams.pagesize
  }
  return request({
    url: '/getTrainingplanPage',
    method: 'post',
    data: data
  })
}

// 数据列表
export function listData(queryParams) {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
    currentPage: queryParams.currentPage,
    pagesize: queryParams.pagesize,
    keywords: queryParams.keywords,
    category: queryParams.category, //培训分类 id
    trainMode: queryParams.trainModeId, //培训方式 id
    examMode: queryParams.examMode, //考试方式 id
    startTime: queryParams.startTime, // 开始时间
    endTime: queryParams.endTime, //结束时间
  }
  return request({
    url: '/getTrainingplanList',
    method: 'post',
    data: data
  })
}

// 新增
export function addData(val) {
  const data = {
    projectContent: {
      ascriptionId: store.state.userInfo.ascriptionId,
      title: val.title, //培训名称
      trainTime: val.trainTime, //培训时间
      startTime: val.startTime, //培训开始时间
      endTime: val.endTime, //培训结束时间
      trainContent: val.trainContent, //培训内容
      coursesId: val.coursesId, //关联课程id
      courses: val.courses, //关联课程
      speakerId: val.speakerId, //主讲人 id
      speaker: val.speaker, //主讲人
      educationalPurpose: val.educationalPurpose, //教育目的
      trainObject: val.trainObject, //培训对象
      trainModeId: val.trainModeId, //培训方式 id
      trainMode: val.trainMode, //培训方式
      examModeId: val.examModeId, //考试方式 id
      examMode: val.examMode, //考试方式
      categoryId: val.categoryId, //培训分类 id
      category: val.category, //培训分类
      placeId: val.placeId, //培训地点 id
      place: val.place, //培训地点
      classHours: val.classHours, //培训课时
      credit: val.credit, //培训学分
      thePic: val.thePic, //培训封面图片
      personnelNum: val.personnelNum // 培训人数
    }
  }
  return request({
    url: '/addTrainingplan',
    method: 'post',
    data: data
  })
}

// 获取单条数据
export function getData(theid) {
  const data = {
    theid
  }
  return request({
    url: '/getTrainingplanData',
    method: 'post',
    data: data
  })
}

// 修改
export function updateData(val) {
  const data = {
    projectContent: {
      theid: val.theid, //id
      title: val.title, //培训名称
      trainTime: val.trainTime, //培训时间
      trainContent: val.trainContent, //培训内容
      coursesId: val.coursesId, //关联课程id
      courses: val.courses, //关联课程
      speakerId: val.speakerId, //主讲人 id
      speaker: val.speaker, //主讲人
      educationalPurpose: val.educationalPurpose, //教育目的
      trainObject: val.trainObject, //培训对象
      trainModeId: val.trainModeId, //培训方式 id
      trainMode: val.trainMode, //培训方式
      examModeId: val.examModeId, //考试方式 id
      examMode: val.examMode, //考试方式
      categoryId: val.categoryId, //培训分类 id
      category: val.category, //培训分类
      placeId: val.placeId, //培训地点 id
      place: val.place, //培训地点
      classHours: val.classHours, //培训课时
      credit: val.credit, //培训学分
      thePic: val.thePic, //培训封面图片
      startTime: val.startTime, //培训开始时间
      endTime: val.endTime, //培训结束时间
    }
  }
  return request({
    url: '/updateTrainingplan',
    method: 'post',
    data: data
  })
}

// 删除
export function delData(theid) {
  const data = {
    theid
  }
  return request({
    url: '/delTrainingplan',
    method: 'post',
    data: data
  })
}

// 批量删除   idListStr id列表  逗号隔开
export function delMultiData(idListStr) {
  const data = {
    idListStr
  }
  return request({
    url: '/delMultipleTrainingplan',
    method: 'post',
    data: data
  })
}

// 下拉框
export function getSelect() {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
  }
  return request({
    url: '/getTrainingplanComboBox',
    method: 'post',
    data: data
  })
}

// 主讲人下拉
export function teacherList(queryParams) {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
    currentPage: queryParams.currentPage,
    pagesize: queryParams.pagesize,
  }
  return request({
    url: '/getLecturerList',
    method: 'post',
    data: data
  })
}

// 修改启用状态  enable 启用状态  0-未启用 1-已启用
export function getEnable(theid, enable) {
  const data = {
    projectContent: {
      theid,
      enable
    }
  }
  return request({
    url: '/changeEnableTrainingplan',
    method: 'post',
    data: data
  })
}

// 关联课程 下拉
export function getCourselect(queryParams) {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
    currentPage: queryParams.currentPage,
    pagesize: queryParams.pagesize,
  }
  return request({
    url: '/getCurriculumList',
    method: 'post',
    data: data
  })
}
// 关联课程 列表
export function getCourse(theid) {
  const data = {
    theid
  }
  return request({
    url: '/getCurriculumData',
    method: 'post',
    data: data
  })
}